define(
	[
		'require'
	],
	function(require){
		var Controller = Ember.Controller.extend({
			formTitle: "银监会动态监测指标日报",
			baseNameDate: 
		        {	
		        	 "count_name": "系统成功交易量",
	                 "success_count_name": "系统交易总量",
	                 "success_rate_name": "系统交易成功率%"
		        },
		     baseBottomNameDate: 
		        {	
		        	 "count_name": "当期交易量",
	                 "success_count_name": "上期交易量",
	                 "success_rate_name": "变化率%"
		        },

		    groupName: Ember.computed(function(){
		    	var ctrl = this,
		    		arr = [];

		    	var num = 16;
		    	for(var i=0;i<num;i++){
		    		arr.push(ctrl.get("baseNameDate"));
		    	}

		    	return Ember.A(arr);
		    }),

		    groupNameBottom: Ember.computed(function(){
		    	var ctrl = this,
		    		arr = [];

		    	var num = 5;
		    	for(var i=0;i<num;i++){
		    		arr.push(ctrl.get("baseBottomNameDate"));
		    	}

		    	return Ember.A(arr);
		    }),

		    MonitoringIndex1: Ember.A(["核心业务系统_资金变动类","核心业务系统_非资金变动类","综合前置系统_大小额支付前置系统","综合前置系统_ATM前置系统","综合前置系统_银联前置系统","综合前置系统_超级网银前置系统","综合前置系统_POS渠道","综合前置系统_第三方存管前置系统","信用卡系统_电话银行渠道","信用卡系统_手机银行渠道","信用卡系统_ATM渠道","信用卡系统_POS渠道","网上银行系统_个人网银","网上银行系统_企业网银","电话银行系统","手机银行"]),
		    MonitoringIndex2: Ember.A(["网上银行交易变化率","电话银行交易变化率","手机银行交易变化率","ATM交易变化率","POS交易变化率"]),
		    
		    filterData: function(result){
		    	var arr1 = [];
		    	var arr2 = [];
		    	var data1 = this.get("MonitoringIndex1");
		    	var data2 = this.get("MonitoringIndex2");

		    	data1.forEach(function(node){
					if(result[node]){
		    			if(!result[node]["count"]){
		    				result[node]["count"] = "-";
		    			}
		    			if(!result[node]["success_count"]){
		    				result[node]["success_count"] = "-";
		    			}
		    			if(!result[node]["success_rate"]){
		    				result[node]["success_rate"] = "-";
		    			}
		    			arr1.push(result[node]);
		    		}else{
		    			arr1.push({ "count": "-",
				                "success_count": "-",
				                "success_rate": "-"});
		    		}
				});
				data2.forEach(function(node){
					if(result[node]){
		    			if(!result[node]["this_count"]){
		    				result[node]["this_count"] = "-";
		    			}
		    			if(!result[node]["history_count"]){
		    				result[node]["history_count"] = "-";
		    			}
		    			if(!result[node]["count_rate"]){
		    				result[node]["count_rate"] = "-";
		    			}
		    			arr2.push(result[node]);
		    		}else{
		    			arr2.push({ "this_count": "-",
				                "history_count": "-",
				                "count_rate": "-"});
		    		}
				});

		    	return {indexTop:Ember.A(arr1),indexBottom:Ember.A(arr2)};

		    	
		    },
			startDate:Ember.computed(function(){
				var date = new Date(new Date() - timeD_value - 3600000*24);
				date.setHours(0);
				date.setMinutes(0);
				date.setSeconds(0);
				date.setMilliseconds(0);
				date.setSeconds(0);
				date.setMilliseconds(0);
				date.setDate(date.getDate()+1);
				return new Date(+date);
			}),
			endDate:Ember.computed(function(){
				var date = new Date(new Date() - timeD_value);
				date.setHours(0);
				date.setMinutes(0);
				date.setSeconds(0);
				date.setMilliseconds(0);
				date.setSeconds(0);
				date.setMilliseconds(0);
				date.setDate(date.getDate()+1);
				return new Date(+date);
			}),
			reportformData: function(){
				var ctrl = this;
				var params = {
					"startDate": +this.get("startDate"),
					"endDate": +this.get("endDate")
				}
				var newArray = [],
					newObject;

				ctrl.set("tipTitle","");

				return this.store.ajax("GET", "report/yjh/trade/indicator",params)
				.then(function(response){
					var performances = response.performances;


					var index = ctrl.filterData(performances[0]);
					ctrl.set("groupData",index);

				});
			},
			url:"report/yjh/download",
			actions: {
				timeRangesChange: function(timeRange){
					this.set("startDate",timeRange.startDate);
					this.set("endDate",timeRange.endDate);

					this.reportformData();
				},
				export: function(){
					var ctrl = this,
						startDate = +ctrl.get("startDate"),
						endDate = +ctrl.get("endDate");
						
					confirmDialog("确定要导出报表吗？")
					.then(function(){
						
						var url="/front/rest/apm/"+ctrl.get("url")+"?startDate="+startDate+"&endDate="+endDate+"&token="+encodeURIComponent($.cookie("token"));
						window.location.href = url;
						// if(!window.location.port){
						// 	window.location.port = "8080";
						// }
					});
				}
			}
		});

		APM.FormBankingController = Controller;
		return Controller;
	}
);